<?php
/**
 *
 * @author crystal
 * @version 
 */
require_once 'Zend/View/Interface.php';

/**
 * BlockNews helper
 *
 * @uses viewHelper Zend_View_Helper
 */
class Zend_View_Helper_BlockNews {
	
	/**
	 * @var Zend_View_Interface 
	 */
	public $view;
	
	/**
	 * 
	 */
	public function blockNews($new, $role = null) {
        $reg = Zend_Registry::getInstance();
		$res = "";
		$res .= "<div class='block_news'>";
        $res .= "<div class='title'>";
    		if ($new['title'] != null){
    			$res .= $new['title'];
    		} else {
  		        $res .= "No title !";
    		}
        $res .= "</div>";
        
		if ($new['description'] != null){
			$res .= "<div class='description'>";
            $photos = $new['pictures_new'];
            if ($photos != null)
            foreach ($photos as $photo){
                $res .= "<a class='single_image' href='" . $this->view->baseUrl(Application_Model_PathsService::getInstance()->get("news", false, array('web' => true))) . $photo['file_name'] . "'>";
                    $res .= "<img src='" . $this->view->baseUrl(Application_Model_IconService::getInstance()->getIconPath("news", $photo['file_name'], array('y' =>200))) . " '/>";
                $res .= "</a>"; 
            }
			$res .= $new['description'];
			$res .= "</div>";
		}
		$bottomData = "";
		if ($new['date_create']){
			$bottomData .= "<div class='date'>";
			$bottomData .= date('j.m.o', $new['date_create']);
			$bottomData .= "</div>";
		}
		if ($reg->acl->isAllowed($role, 'remove_news')){
			$bottomData .= "<div class='button'><a href='" .
						$this->view->url( array('controller' => 'index', 'action' => 'del', 'id' => $new['id'])) .
						"'>Видалити</a></div>";
        }
		if ($reg->acl->isAllowed($role, 'edit_news')){
            $bottomData .= "<div class='button'><a href='" .
						$this->view->url( array('controller' => 'index', 'action' => 'edit', 'id' => $new['id'])) .
						"'>Редагувати</a></div>";
		}
		if ($bottomData != ""){
			$res .= "<div class='bottom_data'>" . $bottomData . "</div>";
		}
		$res .= "</div>";
		return $res;
	}
	
	/**
	 * Sets the view field 
	 * @param $view Zend_View_Interface
	 */
	public function setView(Zend_View_Interface $view) {
		$this->view = $view;
	}
}

